home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / bin / httpd / Solaris_x86 / AT-generate.cgi < prev    next >
Text File  |  1997-03-07  |  28KB  |  838 lines

  1. #!/bin/sh
  2. perl=/tmp/httpd/.excite/perl
  3. eval "exec $perl -x $0 $*"
  4. #!perl
  5.  
  6. ## Copyright (c) 1996 Excite, Inc.
  7. ##
  8. ## This CGI script allows users to generate an Excite, Inc. database
  9. ## query page and result page. Naturally, there are plenty of security
  10. ## concerns associated with this scheme.
  11. ##
  12. ## This script appears as several different web pages, depending on
  13. ## its invocation. If invoked with a 'db=<database>' argument, the
  14. ## script prints out the configuration information for a particular
  15. ## database and then allows the user to input a description of the
  16. ## database for the pages it will generate. If
  17. ## invoked with 'Generate=Generate', 'dbname=<database>',
  18. ## 'describe=<description>', and 'unprefix=<unprefix>' 
  19. ## it will generate files for a database which has an existing database 
  20. ## configuration file. 
  21. ## Without any of these arguments, it displays a list of currently 
  22. ## existing database.conf files, and allows the user to choose a database 
  23. ## for which to generate pages.
  24.  
  25. BEGIN {
  26.   $root = "/tmp/httpd/.excite";
  27.   die "Invalid root directory '$root'\n" unless -d $root;
  28.   unshift(@INC, "$root/perllib");
  29. }
  30.  
  31. $| = 1;  ## don't buffer output
  32.  
  33. require 'os_functions.pl';
  34. require 'architext.pl';
  35. require 'architextConf.pl';
  36. require 'architext_map.pl';
  37.  
  38. $query_banner = &Architext'queryBanner();
  39.  
  40. %form = &Architext'readFormArgs;
  41. $form{'db'} = $form{'dbname'} unless $form{'db'};
  42. %attr = &ArchitextConf'readConfig("$root/Architext.conf", $form{'db'});
  43.  
  44. if (&Architext'remoteMode($root)) {
  45.     $helppath = &Architext'helpPath();
  46. } else {
  47.     $helppath = $attr{'ArchitextURL'};
  48. }
  49.  
  50. $script_suffix = &Architext'scriptSuffix();
  51. $scriptname = "AT-generate$script_suffix";
  52.  
  53. ## check for password, if one is specified in Architext.conf
  54. ## if it doesn't appear as a form arg, present password page
  55. $password = &Architext'password($attr{'ArchitextURL'},
  56.                 $scriptname,
  57.                 $attr{'Password'}, 
  58.                 %form) if $attr{'Password'};
  59.  
  60. $postpass = 
  61.     "<INPUT TYPE=\"hidden\" NAME=\"$password\" VALUE=\"$attr{'Password'}\">" if
  62.     ($attr{'Password'});
  63. $getpass = "?$password=$attr{'Password'}" if $postpass;
  64.  
  65. ## remind users where they need to move generated scripts
  66. if ($form{'moveinfo'}) {
  67.     &Architext'printHeader($attr{'ArchitextURL'},
  68.                "About Moving Query Scripts");
  69.     $search = "<b>AT-$form{'dbname'}search$script_suffix</b>";
  70.     
  71.     print <<EOF;
  72. <p> You have generated the appropriate script necessary to perform
  73. searches on this collection, but they must be moved to your
  74. <b>cgi-bin</b> directory before you can actually begin searching.
  75. <p> Copy $search $gather from <b>$attr{'ConfigRoot'}</b> to
  76. <b>$attr{'CgiBin'}</b>, and you will able to start searching on your
  77. collection.
  78.  
  79. <p> 
  80. <FORM ACTION="AT-admin$script_suffix" METHOD=POST>
  81. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'dbname'}">
  82. <INPUT TYPE="submit" NAME="Admin" VALUE="Admin">
  83. Go back to the main admin page for this collection.
  84. $postpass
  85. </FORM><BR>
  86. EOF
  87.     ;
  88.     &Architext'Copyright($attr{'ArchitextURL'});
  89.     exit;
  90. }
  91.  
  92. if ($form{'Dump'}) {
  93.     &Architext'printHeader($attr{'ArchitextURL'},
  94.                "View $form{'Type'} logfile");
  95.  
  96.     if (! -e $form{'File'}) {
  97.     &Architext'exitError($attr{'ArchitextURL'},
  98.                  "Couldn't find '$form{'File'}'");
  99.     }
  100.     print "<hr><b>Collection Status</b><ul>\n";
  101.     &Architext'printStatus($form{'db'}, $root, $attr{'ConfigRoot'},
  102.                    $attr{'ArchitextURL'}, $helppath,
  103.                    $attr{'CollectionRoot'},
  104.                    $attr{'CgiBin'});
  105.     print "</ul><hr>\n";
  106.     print "\n<pre>\n";
  107.     open(LOG, "$form{'File'}");
  108.     while (<LOG>) {
  109.     print;
  110.     }
  111.     close(LOG);
  112.     print "\n</pre>\n<hr>";
  113.     $filestub = $form{'File'};
  114.     $filestub =~ s|\.\w{3,4}$||;
  115.     print <<EOF;
  116. <b>Possible Actions:</b>
  117. <p><FORM ACTION="AT-generate$script_suffix" METHOD=POST>
  118. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  119. <INPUT TYPE="submit" NAME="Reload" VALUE="Reload">
  120. Reload this page, in case the log file or status  has changed.
  121. <INPUT TYPE="hidden" NAME="Dump" VALUE="dummy">
  122. <INPUT TYPE="hidden" NAME="File" VALUE="$form{'File'}">
  123. <INPUT TYPE="hidden" NAME="Type" VALUE="$form{'Type'}">
  124. $postpass
  125. </FORM><BR>
  126.  
  127. EOF
  128.     ;
  129.     if (! ($form{'Type'} eq 'progress')) {
  130.     print <<EOF;
  131. <p><FORM ACTION="AT-generate$script_suffix" METHOD=POST>
  132. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  133. <INPUT TYPE="submit" NAME="Progress" VALUE="Progress">
  134. Show the contents of the progress log file.
  135. <INPUT TYPE="hidden" NAME="Dump" VALUE="dummy">
  136. <INPUT TYPE="hidden" NAME="File" VALUE="$filestub.prog">
  137. <INPUT TYPE="hidden" NAME="Type" VALUE="progress">
  138. $postpass
  139. </FORM><BR>
  140.  
  141. EOF
  142.     ;
  143.     }
  144.     if (! ($form{'Type'} eq 'verbose')) {
  145.     print <<EOF;
  146. <p><FORM ACTION="AT-generate$script_suffix" METHOD=POST>
  147. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  148. <INPUT TYPE="submit" NAME="Verbose Log" VALUE="Verbose Log">
  149. Show the contents of the verbose log file.
  150. <INPUT TYPE="hidden" NAME="Dump" VALUE="dummy">
  151. <INPUT TYPE="hidden" NAME="File" VALUE="$filestub.log">
  152. <INPUT TYPE="hidden" NAME="Type" VALUE="verbose">
  153. $postpass
  154. </FORM><BR>
  155.  
  156.  
  157. EOF
  158.     ;
  159.     }
  160.     if (! ($form{'Type'} eq 'error')) {
  161.     print <<EOF;
  162. <p><FORM ACTION="AT-generate$script_suffix" METHOD=POST>
  163. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  164. <INPUT TYPE="submit" NAME="Errors" VALUE="Errors">
  165. Show the contents of the error log file.
  166. <INPUT TYPE="hidden" NAME="Dump" VALUE="dummy">
  167. <INPUT TYPE="hidden" NAME="File" VALUE="$filestub.err">
  168. <INPUT TYPE="hidden" NAME="Type" VALUE="error">
  169. $postpass
  170. </FORM><BR>
  171.  
  172.  
  173. EOF
  174.     ;
  175.     }
  176.     print <<EOF;
  177. <p><FORM ACTION="AT-admin$script_suffix" METHOD=POST>
  178. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  179. <INPUT TYPE="submit" NAME="Admin" VALUE="Admin">
  180. Go back to the admin page for this collection.
  181. $postpass
  182. </FORM><BR>
  183.  
  184. EOF
  185.     ;
  186.     &Architext'Copyright($attr{'ArchitextURL'});
  187.     exit(0);
  188. }
  189.  
  190. if ($form{'Status'}) {
  191.     &Architext'printHeader($attr{'ArchitextURL'}, 
  192.                    "View Indexing Logfiles: $form{'db'}");
  193.     print "<p> This page provides access to the three log files that the indexing process creates.  \n";
  194.     print "<hr><b>Collection Status</b><ul>\n";
  195.     &Architext'printStatus($form{'db'}, $root, $attr{'ConfigRoot'},
  196.                    $attr{'ArchitextURL'}, $helppath,
  197.                    $attr{'CollectionRoot'},
  198.                    $attr{'CgiBin'});
  199.     print "</ul>\n";
  200.     $logname = "AT-$form{'db'}.log";
  201.     $progname = "AT-$form{'db'}.prog";
  202.     $errname = "AT-$form{'db'}.err";
  203.     $urlpath = "$root/collections";
  204.     
  205. print <<EOF;
  206. <p><hr>
  207. <b>Logfiles:</b>
  208. <p>
  209. <FORM ACTION="AT-generate$script_suffix" METHOD="POST">
  210. <INPUT TYPE="hidden" NAME="Dump" VALUE="dummy">
  211. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  212. <INPUT TYPE="hidden" NAME="Type" VALUE="progress">
  213. <INPUT TYPE="hidden" NAME="File" VALUE="$urlpath/$progname">
  214. <INPUT TYPE="submit" VALUE="Progress"> Show the progress of the indexing 
  215. process.
  216. $postpass
  217. </FORM>
  218. <p>
  219. <FORM ACTION="AT-generate$script_suffix" METHOD="POST">
  220. <INPUT TYPE="hidden" NAME="Type" VALUE="verbose">
  221. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  222. <INPUT TYPE="hidden" NAME="Dump" VALUE="dummy">
  223. <INPUT TYPE="hidden" NAME="File" VALUE="$urlpath/$logname">
  224. <INPUT TYPE="submit" VALUE="Verbose log"> Show a detailed log of
  225. the indexing process.
  226. $postpass
  227. </FORM>
  228. <p>
  229. <FORM ACTION="AT-generate$script_suffix" METHOD="POST">
  230. <INPUT TYPE="hidden" NAME="Type" VALUE="error">
  231. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  232. <INPUT TYPE="hidden" NAME="Dump" VALUE="dummy">
  233. <INPUT TYPE="hidden" NAME="File" VALUE="$urlpath/$errname">
  234. <INPUT TYPE="submit" VALUE="Errors"> Show any errors that might
  235. have occured during indexing.
  236. $postpass
  237. </FORM>
  238. <hr>
  239. <b>Possible Actions:</b>
  240. <p>
  241. <FORM ACTION="AT-admin$script_suffix" METHOD=POST>
  242. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  243. <INPUT TYPE="submit" NAME="Admin" VALUE="Admin">
  244. Go back to the admin page for this collection.
  245. $postpass
  246. </FORM><BR>
  247. EOF
  248.     ;
  249.     &Architext'Copyright($attr{'ArchitextURL'});
  250.     exit(0);
  251. }
  252.  
  253. if ($form{'Generate'}) {
  254.     if ($form{'qtemplate'}) {
  255.     if ((! -e $form{'qtemplate'}) || (! -r $form{'qtemplate'})) {
  256.         $tmessage = "<b> The template file you specified, '$form{'qtemplate'}', is not readable or does not exist. Please try again.</b>";
  257.         $form{'qpage'} = "";
  258.     }
  259.     }
  260.     if ($form{'ExciteButton'} && ($form{'bltext'} && (! $form{'backlink'}))) {
  261.     $tmessage = "<b> If you provide linktext, you must provide a backlink URL as well.</b>";
  262.     $form{'qpage'} = "";
  263.     }
  264.     if ($form{'ExciteButton'} && ((! $form{'bltext'}) && $form{'backlink'})) {
  265.     $tmessage = "<b> If you provide a backlink URL, you must also provide linktext.</b>";
  266.     $form{'qpage'} = "";
  267.     }
  268.     if (length($form{'bltext'}) > 20) {
  269.     $tmessage = "<b>Please limit the linktext to 20 characters or fewer.</b>";
  270.     $form{'qpage'} = "";
  271.     }
  272.     if ($form{'rtemplate'}) {
  273.     if ((! -e $form{'rtemplate'}) || (! -r $form{'rtemplate'})) {
  274.         $tmessage = "<b> The template file you specified, '$form{'rtemplate'}', is not readable or does not exist. Please try again.</b>";
  275.         $form{'qpage'} = "";
  276.     }
  277.     }
  278.     if (! -d "$form{'unprefix'}") {
  279.     $tmessage = "<b> The path prefix you specified, '$form{'unprefix'}' does not exist, or is not a directory.  Please try again.</b>";
  280.     $form{'qpage'} = "";
  281.     }
  282.     if ($form{'qpage'} && $form{'unprefix'}) {
  283.     ## Assuming all the relevant configuration options are specified
  284.     ## as form arguments, this mode generates the pages.
  285.     ## also checks for required elements 
  286.  
  287.     ## Header again
  288.     &Architext'printHeader($attr{'ArchitextURL'}, 
  289.                    "Search Page Generation: $form{'dbname'}");
  290.  
  291.     if (!$form{'dbname'}) { 
  292.         &Architext'exitError($attr{'ArchitextURL'},
  293.                  "Index specified with no dbname."); }
  294.  
  295.     ## Can we read the db.conf file?
  296.     $dbconfig = $root . "/collections/" . $form{'dbname'} . ".conf";
  297.     if (-e $dbconfig && ! -r $dbconfig) {
  298.         &Architext'exitFileError($attr{'ArchitextURL'},
  299.                      $dbconfig, 
  300.                      "does not exist or is not readable."); }
  301.     
  302.     ## create the default html pages here.
  303.     ## on the query.html page to produce the search$script_suffix script
  304.     &simpleQueryPage();
  305.     &simpleSearchScript();
  306.     
  307.     $simplepage = $form{'qpage'};
  308.     $simplepage .= ".html" unless $simplepage =~ /\.html$/;
  309.     
  310.     ## set up proper arguments for moving scripts to cgi-bin
  311.     $form{'qname'} = $simplepage;
  312.     $form{'qscript'} = "AT-$form{'dbname'}search$script_suffix";
  313.         $files = "<b>$form{'qscript'}</b>";
  314.  
  315.     if ($form{'Move'}) {
  316.         $exit = ©_search_file("$root/$form{'qscript'}", 
  317.                       $attr{'CgiBin'}, $root, $form{'dbname'})
  318.         unless ($root eq $attr{'CgiBin'}); 
  319.         if (! $exit) {
  320.         ## Let the user know the generation was successful.
  321.             print "<H2>Generation successful.</H2>\n";
  322.         print "<p>\n";    
  323.             &remove_files("$root/$form{'qscript'}") unless
  324.         (($root eq $attr{'CgiBin'}) || (&os_name() =~ /NT/));
  325.         ## print "<h2> Moving successful. </h2>\n<p>";
  326.  
  327.         print <<EOF;
  328. Your <b>cgi</b> scripts ($files)
  329. have been generated and installed in your
  330. <b>cgi-bin</b> directory, <b>$attr{'CgiBin'}</b>.
  331. EOF
  332. ;
  333.  
  334. if (-e "$root/collections/$form{'dbname'}.last") {
  335. print <<EOF;
  336. <p>Since you have already created your indexes for this document collection, 
  337. you can now 
  338. <A HREF="$attr{'ArchitextURL'}$form{'qname'}">
  339. <b>Start Searching!</b></a>
  340. EOF
  341. ;
  342. }
  343. print <<EOF;
  344. <p> Once you have tested <b>$form{'qname'}</b> to your liking, 
  345. feel free to move it from the Excite administration directory
  346. (<b>$attr{'ConfigRoot'}</b>) into a directory better suited to 
  347. your needs.
  348. EOF
  349.     ;
  350. } else {
  351.     $warn = &Architext'errorIcon($attr{'ArchitextURL'});
  352. print <<EOF;
  353. <h2>${warn}Problem moving '$files' from 
  354. $root to $attr{'CgiBin'} -- $!</h2>
  355.  
  356. <p>Your scripts have been generated, but they were not copied
  357. into your <b>cgi-bin</b> (<b>$attr{'CgiBin'}</b>) directory because
  358. an error was encountered (probably a permissions problem)
  359. while moving the files. <p>$warn<b>IMPORTANT:</b> Before you can do queries, 
  360. you will either need to move the script that
  361. was just generated ($files) from <b>$root</b> 
  362. into <b>$attr{'CgiBin'}</b>, or
  363. you can try to <b>Generate</b> the scripts again after investigating
  364. the problem.
  365. EOF
  366.     ;
  367. }
  368. } else {
  369.     $warn = &Architext'errorIcon($attr{'ArchitextURL'});
  370.     ## user's cgi-bin was not writeable, so we won't try to move 
  371.     ## the scripts there
  372.     print <<EOF;
  373.  
  374. <h2> ${warn}Scripts generated, but not moved. </h2>
  375. <p> Your scripts have been generated, but were not copied into your
  376. cgi-bin directory (<b>$attr{'CgiBin'}</b>), because it
  377. is not writeable by the userid your Web server is running under.
  378. <p>$warn<b>IMPORTANT: Before you can being making queries, you must copy the 
  379. CGI scripts that were generated into your cgi-bin directory.</b>
  380.  
  381. <p> Copy $files from the directory
  382. <b>$root</b> to the cgi-bin directory, and you
  383. can begin making queries.
  384.  
  385. EOF
  386.     ;
  387. }
  388.  
  389. print <<EOF;
  390. <p> <b>SECURITY ISSUE:</b>  Remember that by making the query page available
  391. to users of your Web site, you are giving them easy access to all
  392. the pages on your site that have been indexed.  If you have sensitive
  393. information that you do not wish to be available to every user of
  394. your Web site, consider leaving those files out of your indexes, or
  395. consider making the search page secure in order to restrict access to it.
  396. <hr><b>Possible Actions:</b>
  397. EOF
  398.     ;
  399. if (! ((-e "$root/collections/$form{'dbname'}.last") ||
  400.        (-e "$root/collections/$form{'dbname'}.pid") ||
  401.        (-e "$root/collections/new/$form{'dbname'}.err")))
  402. {                   
  403.     print <<EOF;
  404. <p> <FORM ACTION="AT-index$script_suffix" METHOD=POST>
  405. <INPUT TYPE="submit" NAME="Indexing" VALUE="Index">
  406. Create an index for this collection.
  407. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'dbname'}">
  408. $postpass
  409. </FORM><BR>
  410. EOF
  411.     ;
  412. }
  413.  
  414. if ((-e "$root/collections/$form{'dbname'}.pid") 
  415.     || (-e "$root/collections/$form{'dbname'}.last")
  416.     || (-e "$root/collections/new/$form{'dbname'}.err" )) {
  417. print <<EOF;
  418. <p> <FORM ACTION="AT-generate$script_suffix" METHOD=POST>
  419. <INPUT TYPE="submit" NAME="Status" VALUE="Status">
  420. Check the status of indexing on this collection.
  421. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'dbname'}">
  422. $postpass
  423. </FORM><BR>
  424.  
  425. EOF
  426.     ;
  427. }
  428.     print <<EOF;
  429. <p> 
  430. <FORM ACTION="AT-admin$script_suffix" METHOD=POST>
  431. <INPUT TYPE="submit" NAME="Admin" VALUE="Admin">
  432. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'dbname'}">
  433. Go back to the admin page for this collection.
  434. $postpass
  435. </FORM><BR>
  436.  
  437. EOF
  438.     ;                
  439.     &Architext'Copyright($attr{'ArchitextURL'});
  440.     exit(0);
  441.     } else {
  442.     ## required elements were not passed in.
  443.     $message = "<b>You didn't enter a value for a required field.  Please try again.</b>";
  444. $message = $tmessage if $tmessage;
  445.     $form{'db'} = $form{'dbname'};
  446.     }
  447. if ($form{'db'}) {
  448.     ## Print out configuration options for an already-existing
  449.     ## database so the user knows what will happen upon page generation
  450.  
  451.     ## Dump our standard header
  452.     &Architext'printHeader($attr{'ArchitextURL'},
  453.                "Search Page Generation: $form{'db'}");
  454.  
  455.     ## Check for the desired database.conf file.
  456.     $dbconfig = $root . "/collections/" . $form{'db'} . ".conf";
  457.     if (! -r $dbconfig) { 
  458.     &Architext'exitFileError($attr{'ArchitextURL'},
  459.                  $dbconfig, "does not exist"); }
  460.  
  461.     ## Read all the configuration information.
  462.     ## %attr = &ArchitextConf'readConfig("$root/Architext.conf", $form{'db'});
  463.  
  464.     ## advise the user if required fields were not passed in
  465.     $warn = &Architext'errorIcon($attr{'ArchitextURL'}); 
  466.     print "$warn$message" if $message;
  467.  
  468.     print "<p> The collection you have chosen has ";
  469.     print "the following characteristics:\n";
  470.     ## Print the form.
  471.     ## This form is just a little list of the options.
  472.     &Architext'collectionCharacteristics($form{'db'}, $helppath, %attr); 
  473.     &printForm($form{'db'});
  474.     if ($getpass) {
  475.     $getpass .= "&";
  476.     } else {
  477.     $getpass = "?";        
  478.     }
  479.     $getpass .= "db=$form{'db'}";
  480.     &Architext'Copyright($attr{'ArchitextURL'});
  481.     exit(0);
  482.  
  483. } else {
  484.     ## Print out the top-level screen: scan the root directory for
  485.     ## db.conf files, and allow the user to initialize a new db.conf
  486.     ## file.
  487.  
  488.     opendir(CONF, "$root/collections");
  489.     @dbconf = grep(/\.conf$/, readdir(CONF));
  490.  
  491.     &Architext'printHeader($attr{'ArchitextURL'},"Search Page Generation");
  492.     if ($#dbconf > -1) {
  493.     print <<EOF;
  494. <FORM ACTION="AT-generate$script_suffix" METHOD=POST>
  495. Choose a document collection for which to generate query and result pages.<P>
  496. <DL>
  497. <DT> 
  498. Existing <a href="${helppath}AT-helpdoc.html#Document Collections">document collections:</a> <DD>
  499. <SELECT NAME="db" SIZE=5>
  500. EOF
  501.     ;
  502.     for (@dbconf) {
  503.     s|\.conf$||;
  504.     next if $_ eq 'Architext';
  505.     print "<OPTION> $_\n";
  506.     }
  507.     print <<EOF;
  508. </SELECT>
  509. </DL>
  510. <INPUT TYPE="submit" NAME="select" VALUE="Select">
  511. $postpass
  512. </FORM><BR>
  513. EOF
  514.     ;
  515. } else {
  516.     print <<EOF;
  517. <p> There are no document collections currently defined.  Please
  518. click on the configure button to go to the collection configuration
  519. screen.
  520. <FORM ACTION="AT-config$script_suffix" METHOD=POST>
  521. <INPUT TYPE="submit" VALUE="Configure">
  522. $postpass
  523. </FORM><BR>
  524. EOF
  525.     ;
  526. }
  527.     &Architext'Copyright($attr{'ArchitextURL'});
  528. }
  529.  
  530. ## Prints an input line for a form.
  531. sub printLineItem {
  532.     local($name, $text) = @_;
  533.     local($val);
  534.     $text = $name unless $text;
  535.     $val = eval "\$attr{$name}";
  536.     print qq(<li> <a href="${helppath}AT-helpdoc.html#$text">$text:</a> $val\n);
  537. }
  538.  
  539. ## Prints out the Architext form. Uses dynamic scoping to ensure that
  540. ## the values in the %attr array are properly set.
  541. sub printForm {
  542.     local($db) = shift;
  543.     local ($size) = 30;
  544.     print qq(<FORM ACTION="AT-generate$script_suffix" METHOD=POST>\n);
  545.     if (($attr{'CgiBin'}) && (-w "$attr{'CgiBin'}")) {
  546.     print qq(<INPUT TYPE="hidden" NAME="Move" VALUE="yes">\n);
  547.     }
  548.     $pprefix = $form{'unprefix'} ||
  549.     $attr{'HtmlRoot'};
  550.     $qimage = $form{'qimage'} || 
  551.     "$attr{'ArchitextURL'}pictures/$query_banner";
  552.     $size = (length($pprefix)+10) 
  553.     unless ((length($attr{'HtmlRoot'})+10) < 30);
  554.     $qlength = (length($qimage) + 10); 
  555.     print <<EOF;
  556. <INPUT TYPE="hidden" NAME="qpage" VALUE="AT-$form{'db'}query.html">
  557. <INPUT TYPE="hidden" NAME="unprefix" VALUE="$pprefix">
  558. <p> <b>Optional Information</b><ul>
  559. <p> Enter <a href="${helppath}AT-helpdoc.html#Banner Image">
  560. Banner Image</a> to appear at the top of query and result pages:
  561. <INPUT NAME="qimage" VALUE="$qimage"
  562. SIZE=$qlength>
  563. <p>Enter a <a href="${helppath}AT-helpdoc.html#Brief Description">
  564. brief description</a>
  565.  of the contents of your database for use in 
  566. the query page.  The generated query page will appear in 
  567. <b>$attr{'ConfigRoot'}</b>. 
  568. <TEXTAREA NAME="describe" COLS=60 ROWS=4>$form{'describe'}</TEXTAREA>
  569. <p><INPUT TYPE="checkbox" NAME="ExciteButton" VALUE="ExciteButton" CHECKED>
  570. Allow internet-wide searches on <a href="http://www.excite.com">excite</a> on the generated search page.
  571. EOF
  572.     ;
  573.     if (&Architext'backlinkMode()) {
  574.     $blval = $form{'backlink'} || 
  575.         "http://$ENV{'SERVER_NAME'}:$ENV{'SERVER_PORT'}$attr{'ArchitextURL'}AT-$form{'db'}query.html";
  576.     $blsize = length($blval);
  577.     print <<EOF;
  578. <br>If you would like internet-wide excite searches to provide a link
  579. back to your site, fill in the blanks below:
  580. <ul>
  581. Optional <a href="${helppath}AT-helpdoc.html#Backlink">Backlink:</a>
  582. <INPUT NAME="backlink" VALUE="$blval" SIZE=$blsize><br> 
  583. Optional <a href="${helppath}AT-helpdoc.html#Linktext">Linktext:</a>
  584. <INPUT NAME="bltext" VALUE="$form{'bltext'}" SIZE=30><br>
  585. </ul>
  586. EOF
  587.     ;
  588.     }
  589.     print <<EOF;
  590. </ul>
  591. <b> Advanced Customization Information </b>
  592. <ul>
  593. <p> Enter the name of a <a href="${helppath}AT-helpdoc.html#Query Template">
  594. query template</a> file:
  595. <INPUT NAME="qtemplate" VALUE="$form{'qtemplate'}" SIZE=40>
  596. <p> Enter the name of a <a href="${helppath}AT-helpdoc.html#Query-Results Template">
  597. query-results template</a> file:
  598. <INPUT NAME="rtemplate" VALUE="$form{'rtemplate'}" SIZE=40>
  599. </ul><hr>
  600. <b> Possible Actions:</b>
  601. <p><INPUT TYPE="submit" NAME="generate" VALUE="Generate">
  602. Generate the query pages and scripts need to perform queries.
  603. <INPUT TYPE="hidden" NAME="Generate" VALUE="Generate">
  604. <INPUT TYPE="hidden" NAME="dbname" VALUE="$db">
  605. $postpass
  606. </FORM>
  607. <p> 
  608. <FORM ACTION="AT-admin$script_suffix" METHOD=POST>
  609. <INPUT TYPE="hidden" NAME="db" VALUE="$db">
  610. <INPUT TYPE="submit" NAME="Admin" VALUE="Admin">
  611. Go back to the admin page for this collection.
  612. $postpass
  613. </FORM><BR>
  614.  
  615. EOF
  616.     ;
  617. }
  618.  
  619. ## creates the script that actually performs the searches
  620. sub simpleSearchScript {
  621.     local($scriptname, $preflag, $postflag);
  622.     local($umapfile, %mappings);
  623.     $preflag = $postflag = 0;
  624.     
  625.     $scriptname = "$root/AT-$form{'dbname'}search$script_suffix";
  626.     &remove_files($scriptname);
  627.     open(SCRIPT, ">$scriptname") 
  628.     || &Architext'exitError($attr{'ArchitextURL'},
  629.                 "Could not open '$scriptname' for writing");
  630.     ## standard header information
  631.     if (&non_shell_invocation_ok($attr{'PerlRoot'})) {
  632.     print SCRIPT "#!$attr{'PerlRoot'}\n\n";
  633.     } else {
  634.     print SCRIPT "#!/bin/sh\n";
  635.     $aproot = $attr{'PerlRoot'};
  636.     $aproot =~ s/\\/\\\\/g;
  637.     print SCRIPT "perl=$aproot\n";
  638.     print SCRIPT "eval \"exec \$perl -x \$0 \$*\"\n";
  639.     print SCRIPT "#!perl\n\n";
  640.     }
  641.     $aroot = $root;
  642.     $aroot =~ s/\\/\\\\/g;
  643.     print SCRIPT "\$root = \"$aroot\";\n";
  644.     print SCRIPT "unshift(\@INC, \"\$root/perllib\");\n";
  645.     print SCRIPT "require 'architext_query.pl';\n";
  646.     print SCRIPT "require 'ctime.pl';\n";
  647.     ## insert db specific information here
  648.     print SCRIPT "\$aurl = \"$attr{'ArchitextURL'}\";\n";
  649.     print SCRIPT "\$db = \"$form{'dbname'}\";\n";
  650. $acroot = $attr{'CollectionRoot'};
  651.     $acroot =~ s/\\/\\\\/g;
  652.     print SCRIPT "\$index = \"$acroot\";\n";
  653.     $ahroot = $attr{'HtmlRoot'};
  654.     $ahroot =~ s/\\/\\\\/g;
  655.     print SCRIPT "\$hroot = \"$ahroot\";\n";
  656.     $aexec = $attr{'SearchExecutable'};
  657.     $aexec =~ s/\\/\\\\/g;
  658.     print SCRIPT "\$binary = \"$aexec\";\n";
  659.     ##create the url edit option here by getting all the mappings
  660.     $umapfile = "$root/collections/$form{'dbname'}.usr" 
  661.     if ($attr{'PublicHtml'});
  662.     %mappings = 
  663.     &ArchitextMap'getMappings($attr{'HtmlRoot'},
  664.                    "$root/url.map",
  665.                    $umapfile);
  666.     $urledit = &ArchitextMap'generateURLEdit(%mappings);
  667.     print SCRIPT "\$urledit = '$urledit';\n\n";
  668.  
  669.     $log_file = ", '$root/query.log'" if &Architext'logMode();
  670.  
  671.     print SCRIPT "\%form = &ArchitextQuery'readFormArgs;\n";
  672.     print SCRIPT 
  673.     "&ArchitextQuery'directQuery(\$form{'search'} || '(no search)',\n";
  674.     print SCRIPT "\t\$form{'mode'} || 'concept', \$db, \$form{'source'} || 'local', \$form{'backlink'} || '*', \$form{'bltext'} || '*'$log_file);\n";
  675.     print SCRIPT "print \"Content-type: text/html\\n\\n\";\n";
  676.  
  677.     ## insert standard template code
  678.     open(TEMPLATE, "$root/AT-template.cgi") 
  679.     || &Architext'exitError($attr{'ArchitextURL'},
  680.                 "Could not open '$root/AT-template.cgi'");
  681.  
  682.     while ($tmpstr = <TEMPLATE>) {
  683.         last if ($tmpstr =~ /^___SEPARATOR___/);
  684.     print SCRIPT $tmpstr;
  685.     }
  686.  
  687.     if ($form{'rtemplate'}) {
  688.     ## using template file
  689.     open(TFILE, "$form{'rtemplate'}") 
  690.         || &Architext'exitError($attr{'ArchitextURL'},
  691.                     "Couldn't open '$form{'rtemplate'}'");
  692.     print SCRIPT "print <<EOF;\n";
  693.     while (<TFILE>) {
  694.         $preflag = 1 if /\#\#\#EXCITE\#\#\#/;
  695.         s/\@/\\\@/g;
  696.         print SCRIPT unless $preflag;
  697.     }
  698.     close(TFILE);
  699.     print SCRIPT "\nEOF\n;\n";
  700.     } else {
  701.     ##using 'stock' script
  702.     print SCRIPT "print \"<html><head><title>Excite for Web Servers Search Results</title></head>\\n\";\n"; 
  703.     print SCRIPT "print \"<body BGCOLOR=\\\"#FFFFFF\\\" TEXT=\\\"#000000\\\" LINK=\\\"#FF0000\\\" ALINK=\\\"#0000FF\\\">\";\n";
  704.     $query_banner = &Architext'queryBanner();
  705.     if ($form{'qimage'} =~ $query_banner) {
  706.         $pre_anchor = "<a href=\\\"http://www.excite.com/\\\">";
  707.         $post_anchor = "</a>";
  708.     }
  709.     print SCRIPT "print \"<h1>$pre_anchor<img src=\\\"$form{'qimage'}\\\" BORDER=0>$post_anchor</h1>\\n\";\n";
  710.     }
  711.     
  712.     while (<TEMPLATE>) {
  713.     print SCRIPT $_;
  714.     }
  715.  
  716.     if ($form{'rtemplate'}) {
  717.     open(TFILE, "$form{'rtemplate'}") 
  718.         || &Architext'exitError($attr{'ArchitextURL'},
  719.                     "Could not open '$form{'rtemplate'}");
  720.     while (<TFILE>) {
  721.         s/\@/\\\@/g;    
  722.         print SCRIPT if $postflag;
  723.         if (/\#\#\#EXCITE\#\#\#/) {
  724.         $postflag = 1;
  725.         print SCRIPT "print <<EOF;\n";
  726.         }
  727.     }
  728.     close(TFILE);
  729.     print SCRIPT "\nEOF\n;\n";
  730.     } else {
  731.     print SCRIPT "print \"</body></html>\\n\";\n";
  732.     }
  733.  
  734.     close(SCRIPT);
  735.     close(TEMPLATE);
  736.     $exit = &make_file_executable($scriptname);
  737.     &Architext'exitError($attr{'ArchitextURL'}, 
  738.              "Can't change permissions on '$scriptname' - $!")
  739.     if $exit;
  740.  
  741. }
  742.  
  743. ## prints a default query page with a simple description
  744. sub simpleQueryPage {
  745.     local($simplepage);
  746.     local($exit);
  747.     $simplepage = $form{'qpage'};
  748.     $simplepage .= ".html" unless $simplepage =~ /\.html$/;
  749.     $simplepage = $root . "/" . $simplepage;
  750.     &remove_files($simplepage); 
  751.     open(SPAGE, ">$simplepage") ||
  752.     &Architext'exitFileError($attr{'ArchitextURL'},
  753.                  $simplepage, 
  754.                  "could not be opened for writing.");
  755.     if ($form{'qtemplate'}) {
  756.     ##user is using template file
  757.     open(TEMPLATE, "$form{'qtemplate'}") ||
  758.         &Architext'exitFileError($attr{'ArchitextURL'},
  759.                      $form{'qtemplate'}, 
  760.                      "could not be opened for reading.");
  761.     while (<TEMPLATE>) {
  762.         if (/\#\#\#EXCITE\#\#\#/) {
  763.         &printQueryForm();
  764.         } else {
  765.         print SPAGE $_;
  766.         }
  767.     }
  768.     close(TEMPLATE);
  769.     } else {
  770.  
  771.     print SPAGE "<html><head><title>Excite Searching</title></head>\n";
  772.     $query_banner = &Architext'queryBanner();
  773.     if ($form{'qimage'} =~ $query_banner) {
  774.         $pre_anchor = "<a href=\"http://www.excite.com/\">";
  775.         $post_anchor = "</a>";
  776.     }
  777.     print SPAGE qq(<body BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" ALINK="#0000FF">\n);
  778.     print SPAGE qq(<h1>$pre_anchor<img src="$form{'qimage'}" BORDER=0>$post_anchor</h1>\n) 
  779.         if $form{'qimage'};
  780.  
  781.     $describeit = $form{'describe'};
  782.     print SPAGE "<p><b>Database description:</b> $describeit \n<p>\n"
  783.         if $describeit;
  784.     &printQueryForm();
  785.     print SPAGE "\n</body></html>\n";
  786.     }
  787.     close(SPAGE);
  788.     ## don't copy files if config root and architext root are the same
  789.     if ($root ne $attr{'ConfigRoot'}) {
  790.     $exit = ©_files($simplepage, $attr{'ConfigRoot'});
  791.     &Architext'exitError($attr{'ArchitextURL'},
  792.                  "Cannot copy $simplepage to $attr{'ConfigRoot'}") if $exit;
  793.     }
  794. }
  795.  
  796. ## prints the query form onto the querypage (SPAGE)
  797. sub printQueryForm {
  798.     local($skip_radio);
  799.     local($query_help) = "$attr{'ArchitextURL'}AT-queryhelp.html";
  800.     local($cgi) = $ENV{'SCRIPT_NAME'};
  801.     $cgi =~ s/\/?[^\/]+$//;
  802.     local($excite_button) = &Architext'searchButton();
  803.     local($excited_ad) = &Architext'excitedAd();
  804.     $excite_button = "$attr{'ArchitextURL'}pictures/$excite_button";
  805.     local($excited_label) = "$attr{'ArchitextURL'}pictures/$excited_ad";
  806.     local($search_script) = "$cgi/AT-$form{'dbname'}search$script_suffix";
  807.     open(QFORM, "$root/AT-query.html") ||
  808.     &Architext'exitFileError($attr{'ArchitextURL'},
  809.                  "$root/AT-query.html", 
  810.                  "could not be opened for reading.");
  811.     while (<QFORM>) {
  812.     s/CGI/$search_script/;
  813.     s/BUTTON/$excite_button/;
  814.     s/DOC/$query_help/;
  815.     s/BACKLINK/$form{'backlink'}/;
  816.     s/LINKTEXT/$form{'bltext'}/;
  817.     s/EXCITED/$excited_label/;
  818.     s/QUERY//;
  819.     print SPAGE "$_\n" unless ((/___SEPARATOR___/) || $skip_radio ||
  820.                    (/___END___/));
  821.     $skip_radio = 0 if (/___END___/);
  822.     $skip_radio = 1 if ((/___SEPARATOR___/) && (! $form{'ExciteButton'})); 
  823.     }
  824.     close(QFORM);
  825. }
  826.  
  827. ## returns true if OS can handle #! lines > 32 chars
  828. sub non_shell_invocation_ok {
  829.     local($perlpath) = @_;
  830.     local($os) = &os_name();
  831.     return 0 if ($os eq 'NT');
  832.     return 1 if (($os =~ /BSD/) || ($os =~ /IRIX/)  ||
  833.          ($os =~ /AIX/) || (($os =~ /SunOS/) && (! -e '/vmunix')));
  834.     return 1 if ( length($perlpath) < 30); 
  835.     return 0;            
  836. }
  837.